//                       .::::.
//                     .::::::::.
//                    :::::::::::
//                 ..:::::::::::'
//              '::::::::::::'
//                .::::::::::
//           '::::::::::::::..
//                ..::::::::::::.
//              ``::::::::::::::::
//               ::::``:::::::::'        .:::.
//              ::::'   ':::::'       .::::::::.
//            .::::'      ::::     .:::::::'::::.
//           .:::'       :::::  .:::::::::' ':::::.
//          .::'        :::::.:::::::::'      ':::::.
//         .::'         ::::::::::::::'         ``::::.
//     ...:::           ::::::::::::'              ``::.
//    ```` ':.          ':::::::::'                  ::::..
//                       '.:::::'                    ':'````..
package com.xw.controller.api;

import com.google.common.collect.Maps;
import com.xw.common.Const;
import com.xw.dao.UserConcernMapper;
import com.xw.dao.VideosMapper;
import com.xw.model.SysUserConcern;
import com.xw.service.OrdersService;
import com.xw.service.UserInfoService;
import com.xw.util.AppUtil;
import com.xw.util.JsonData;
import com.xw.util.JsonUtil;
import com.xw.vo.UserConcernVo;
import com.xw.vo.UserInfoVo;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/api/userInfo/")
@Scope("prototype")
public class ApiUserInfoController {

    @Resource
    private UserInfoService userInfoService;

    /**
     * 名师推荐-讲师详情-小程序
     * @param userId
     * @param teacherUserId 讲师id
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "findTeacherDetailMP", method = RequestMethod.POST)
    @ResponseBody
    public Object findTeacherDetailMP(String userId,String teacherUserId) throws Exception {
        //判断传参
        Map map = Maps.newHashMap();
        map.put("userId", userId);
        map.put("teacherUserId", teacherUserId);
        String str = AppUtil.checkIsNull(map);
        if (!str.equals(Const.SUCCESS_CODE_STR)) {
            return JsonData.fail(Const.parameterError(str));
        }
        map.clear();
        map = userInfoService.findTeacherDetailMP(userId,teacherUserId);
        return map;
    }

    /**
     * 名师推荐-名师推荐列表(没有关注的名师)-小程序
     * @param userId
     * @param page
     * @param limit
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "findRecommendTeacherMP", method = RequestMethod.POST)
    @ResponseBody
    public Object findRecommendTeacherMP(String userId, Integer page, Integer limit) throws Exception {
        //判断传参
        Map map = Maps.newHashMap();
        map.put("userId", userId);
        String str = AppUtil.checkIsNull(map);
        if (!str.equals(Const.SUCCESS_CODE_STR)) {
            return JsonData.fail(Const.parameterError(str));
        }
        map.clear();
        map = userInfoService.findRecommendTeacherMP(userId,page,limit);
        return map;
    }


    /**
     * 申请讲师
     *
     * @param request
     * @param userId
     * @param applyReason 理由
     * @param applyUrl    附件地址
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "applyTeacher", method = RequestMethod.POST)
    @ResponseBody
    public Object applyTeacher(HttpServletRequest request, String userId, String applyReason, String applyUrl) throws Exception {
        //判断传参
        Map map = Maps.newHashMap();
        map.put("userId", userId);
        map.put("applyReason", applyReason);
        map.put("applyUrl", applyUrl);
        String str = AppUtil.checkIsNull(map);
        if (!str.equals(Const.SUCCESS_CODE_STR)) {
            return JsonData.fail(Const.parameterError(str));
        }
        map.clear();
        map = userInfoService.applyTeacher(userId, applyReason, applyUrl);
        return map;
    }


    /**
     * @需求描述:展示推荐讲师接口
     * @创建人:whh
     * @创建时间: 2019/11/12
     * @修改需求:
     * @修改人:
     * @修改时间:
     * @需求思路:
     */
    @RequestMapping(value = "showTeachers", method = RequestMethod.POST)
    @ResponseBody
    public Object showTeachersAction(HttpServletRequest request, @RequestBody Map<String, Object> paramsMap) throws Exception {

        UserInfoVo userInfoVo = new UserInfoVo();
        Integer pageNum = null;
        Integer pageSize = null;
        Map<String, Object> userInfomMap = (Map<String, Object>) paramsMap.get("userInfoVo");
        if (null != userInfomMap) {
            JsonUtil.mapToObject(userInfomMap, userInfoVo);
        }
        if (null != paramsMap.get("pageNum")) {
           pageNum = Integer.parseInt(paramsMap.get("pageNum").toString());
        }
        if (null != paramsMap.get("pageSize")) {
            pageSize = Integer.parseInt(paramsMap.get("pageSize").toString());
        }
        Map<String, Object> map = new HashMap<>();
        map.put("userInfoVo", userInfoVo);
        map.put("pageNum",pageNum);
        map.put("pageSize",pageSize);
        return userInfoService.showTeachers(map);
    }


    /**
     * @需求描述:展示我的关注（用户关注的讲师列表接口）
     * @创建人:whh
     * @创建时间: 2019/11/12
     * @修改需求:
     * @修改人:
     * @修改时间:
     * @需求思路:
     */
    @RequestMapping(value = "myCareTeacher", method = RequestMethod.POST)
    @ResponseBody
    public Object myCareTeacherAction(HttpServletRequest request, @RequestBody Map<String, Object> paramsMap) throws Exception {

        //判断传参
        Map<String, Object> map = new HashMap<>();
        String str = AppUtil.checkIsNull(paramsMap);
        if (!str.equals(Const.SUCCESS_CODE_STR)) {
            return JsonData.fail(Const.parameterError(str));
        }
        UserInfoVo userInfoVo = new UserInfoVo();
        Map<String, Object> userInfomMap = (Map<String, Object>) paramsMap.get("userInfoVo");
        JsonUtil.mapToObject(userInfomMap, userInfoVo);

        map.put("userInfoVo", userInfoVo);
        return userInfoService.myCareTeacher(map);
    }

    /**
     * @需求描述:讲师信息
     * @创建人:whh
     * @创建时间: 2019/11/12
     * @修改需求:
     * @修改人:
     * @修改时间:
     * @需求思路:
     */
    @RequestMapping(value = "getTeacherInfo", method = RequestMethod.POST)
    @ResponseBody
    public Object getTeacherInfoAction(HttpServletRequest request, @RequestBody Map<String, Object> paramsMap) throws Exception {

        paramsMap.remove("fansInfoId");
        //判断传参
        String str = AppUtil.checkIsNull(paramsMap);
        if (!str.equals(Const.SUCCESS_CODE_STR)) {
            return JsonData.fail(Const.parameterError(str));
        }

        UserInfoVo userInfoVo = new UserInfoVo();
        Map<String, Object> userInfomMap = (Map<String, Object>) paramsMap.get("userInfoVo");
        JsonUtil.mapToObject(userInfomMap, userInfoVo);
        Map<String, Object> map = new HashMap<>();
        map.put("userInfoVo", userInfoVo);
        if(null != paramsMap.get("userId")){
            map.put("fansInfoId",paramsMap.get("userId"));
        }
        return userInfoService.getTeacherInfo(map);
    }


    /**
     * @需求描述:展示讲师列表
     * @创建人:whh
     * @创建时间: 2019/11/12
     * @修改需求:
     * @修改人:
     * @修改时间:
     * @需求思路:
     */
    @RequestMapping(value = "getTeacherList", method = RequestMethod.POST)
    @ResponseBody
    public Object getTeacherListAction(HttpServletRequest request, @RequestBody Map<String, Object> paramsMap) throws Exception {

        //判断传参
        String str = AppUtil.checkIsNull(paramsMap);
        if (!str.equals(Const.SUCCESS_CODE_STR)) {
            return JsonData.fail(Const.parameterError(str));
        }
        return userInfoService.getTeacherList(paramsMap);
    }

    /**
     * @需求描述:查询用户信息
     * @创建人:whh
     * @创建时间: 2019/11/14
     * @修改需求:
     * @修改人:
     * @修改时间:
     * @需求思路:
     */
    @RequestMapping(value = "findUserInfo", method = RequestMethod.POST)
    @ResponseBody
    public Object findUserInfoAction(HttpServletRequest request, @RequestBody Map<String, Object> paramsMap) throws Exception {

        //判断传参
        String str = AppUtil.checkIsNull(paramsMap);
        if (!str.equals(Const.SUCCESS_CODE_STR)) {
            return JsonData.fail(Const.parameterError(str));
        }
        UserInfoVo userInfoVo = new UserInfoVo();
        Map<String, Object> userInfomMap = (Map<String, Object>)paramsMap.get("userInfoVo");
        JsonUtil.mapToObject(userInfomMap, userInfoVo);
        paramsMap.put("userInfoVo",userInfoVo);
        return userInfoService.findUserInfo(paramsMap);
    }

    /**
     * @需求描述:查询用户我的关注
     * @创建人:whh
     * @创建时间: 2019/11/14
     * @修改需求:
     * @修改人:
     * @修改时间:
     * @需求思路:
     */
    @RequestMapping(value = "getMyCare", method = RequestMethod.POST)
    @ResponseBody
    public Object getMyCareAction(HttpServletRequest request, @RequestBody Map<String, Object> paramsMap) throws Exception {

        //判断传参
        String str = AppUtil.checkIsNull(paramsMap);
        if (!str.equals(Const.SUCCESS_CODE_STR)) {
            return JsonData.fail(Const.parameterError(str));
        }
        UserInfoVo userInfoVo = new UserInfoVo();
        Map<String, Object> userInfomMap = (Map<String, Object>)paramsMap.get("userInfoVo");
        if (null != userInfomMap){
            JsonUtil.mapToObject(userInfomMap, userInfoVo);
        }
        paramsMap.put("userInfoVo",userInfoVo);
        return userInfoService.getMyCare(paramsMap);
    }


    /**
     * @需求描述:查询用户我的粉丝
     * @创建人:whh
     * @创建时间: 2019/11/14
     * @修改需求:
     * @修改人:
     * @修改时间:
     * @需求思路:
     */
    @RequestMapping(value = "findMyFans", method = RequestMethod.POST)
    @ResponseBody
    public Object findMyFansAction(HttpServletRequest request, @RequestBody Map<String, Object> paramsMap) throws Exception {

        //判断传参
        String str = AppUtil.checkIsNull(paramsMap);
        if (!str.equals(Const.SUCCESS_CODE_STR)) {
            return JsonData.fail(Const.parameterError(str));
        }
        UserInfoVo userInfoVo = new UserInfoVo();
        Map<String, Object> userInfomMap = (Map<String, Object>)paramsMap.get("userInfoVo");
        if (null != userInfomMap){
            JsonUtil.mapToObject(userInfomMap, userInfoVo);
        }

        paramsMap.put("userInfoVo",userInfoVo);
        return userInfoService.findMyFans(paramsMap);
    }



//    /**
//     * @需求描述:关注/取消关注讲师
//     * @创建人:whh
//     * @创建时间: 2019/11/14
//     * @修改需求:
//     * @修改人:
//     * @修改时间:
//     * @需求思路:
//     */
//    @RequestMapping(value = "unfollowTeacher", method = RequestMethod.POST)
//    @ResponseBody
//    public Object unfollowTeacherAction(HttpServletRequest request, @RequestBody Map<String, Object> paramsMap) throws Exception {
//
//        //判断传参
//        String str = AppUtil.checkIsNull(paramsMap);
//        if (!str.equals(Const.SUCCESS_CODE_STR)) {
//            return JsonData.fail(Const.parameterError(str));
//        }
//        UserConcernVo UserConcernVo = new UserConcernVo();
//        if (null == paramsMap.get("sysUserConcern")){
//            return JsonData.fail("参数不能为空");
//        }
//        Map<String, Object> userConcernMap = (Map<String, Object>)paramsMap.get("sysUserConcern");
//        JsonUtil.mapToObject(userConcernMap, UserConcernVo);
//
//        if (UserConcernVo.getUserId().equals(UserConcernVo.getTeacherId())){
//            return JsonData.fail("不可以关注自己");
//        }
//        paramsMap.put("userId",UserConcernVo.getUserId());
//        paramsMap.put("teacherId",UserConcernVo.getTeacherId());
//        paramsMap.put("status",UserConcernVo.getStatus());
//        str = AppUtil.checkIsNull(paramsMap);
//        if (!str.equals(Const.SUCCESS_CODE_STR)) {
//            return JsonData.fail(Const.parameterError(str));
//        }
//        paramsMap.clear();
//        paramsMap.put("userConcernVo",UserConcernVo);
//        return userInfoService.unfollowTeacher(paramsMap);
//    }
}


